<!-- 模型文档界面 -->
<template>
  <div class="document-box">
    <div class="line-border">
      <div class="document-box-header">
        <div></div>
        <a-button type="text" class="icon-only-btn button-padding" @click.stop="handleToDownload(propValue?.docUrl, propValue.docName)">
          <i class="iconfont icon-download-2-line"></i>下载文档
        </a-button>
      </div>
      <div class="document-pdf my-scrollbar">
        <preview-pdf v-if="propValue && propValue.docPdfUrl" :url="(propValue?.docPdfUrl as string)" is-height-auto />
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { debounce } from 'g6-fn'

  import PreviewPdf from '@/components/PreviewPdf/index.vue'
  import { fetchDownload, minioApi } from '@/services/api'
  import { waitLoading } from '@/utils'

  import { DetailType } from '../../list/types'
  export interface PropType {
    propValue?: DetailType
  }
  withDefaults(defineProps<PropType>(), {})

  //下载
  const handleToDownload = debounce(async (dataUrl: string, dataFileName: string): Promise<void> => {
    const { data } = await minioApi.download({ fileName: dataUrl })

    waitLoading<ResponseData<any>>(fetchDownload(data, dataFileName), {
      loadingText: '数据准备中,请耐心等待...',
      errorText: '文件下载失败',
      successText: '文件下载成功'
    })
  }, 500)
</script>
<style lang="less" scoped>
  .document-box {
    display: flex;
    align-items: flex-start;
    width: 100%;
    gap: 24px;

    .document-box-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 24px;
      background: @background1;
      align-self: stretch;
      border-bottom: 1px solid @mask1;
      border-top-right-radius: 10px;
      border-top-left-radius: 10px;

      .button-padding {
        padding: 7px 16px;
        gap: 6px;
        color: #1868e9;
      }
    }
  }

  .line-border {
    display: flex;
    width: 100%;
    height: 670px;
    background: #fff;
    border: 1px solid @border1;
    border-radius: 10px;
    flex-direction: column;
  }

  .img-class {
    width: 100%;
  }

  .box-left {
    width: 100%;
  }

  .document-pdf {
    overflow-y: auto;
    // height: 585px;
    height: 100%;
    // min-height: 585px;
  }
</style>
